package com.booby.algorithm.bubble;

import com.booby.algorithm.utils.Utils;

/**
 * 功能描述: 冒泡排序，从大到小
 *
 * @author: lizt
 * @date: 2020/7/31 17:45
 **/

public class MaxToMin {
    public static void main(String[] args) {
        Integer[] arr = {5,7, 3, 2,6, 1, 9, 8,6, 7, 4};
        sorted(arr);
    }

    public static void sorted(Integer[] arr){

        for (int i = 0; i < arr.length; i++) {
            // 初始化参数
            Integer currentIndex = 0;
            Integer nextIndex = 0;
            for (int j = 0; j < arr.length-1 && nextIndex < arr.length; j++) {
                currentIndex = j;
                nextIndex = j + 1;
                if (arr[currentIndex] < arr[nextIndex]){
                    Utils.swap(arr, currentIndex, nextIndex);
                }
            }
        }
//        Utils.print(arr);
    }
}
